<template>
  <!-- 雷达图  图表必须给高和宽度-->
  <div ref="myDiv" class="radar-echart" />
</template>

<script>
// 完成加载过程
// import echarts from 'echarts'
// var echarts = require('echarts')
var echarts = require('echarts/lib/echarts') // 引入echarts主模块
require('echarts/lib/chart/radar') // 引入雷达图
// 引入提示框和标题组件
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')

const arr = {
  person: [
    {
      name: '智翱逸',
      score: 30,
      backboard: 4,
      assist: 7,
      blockShot: 1,
      Steal: 2,
      fault: 3
    },
    {
      name: 'wenbanyama',
      score: 16,
      backboard: 12,
      assist: 4,
      blockShot: 3,
      Steal: 2,
      fault: 2
    },
    {
      name: '奥特曼',
      score: 25,
      backboard: 8,
      assist: 7,
      blockShot: 4,
      Steal: 1,
      fault: 4
    }
  ]
}

const data = []

arr.person.forEach(item => {
  const obj = {}
  obj.name = item.name
  const value = []
  for (const key in item) {
    value.push(item[key])
  }
  value.shift()
  obj.value = value
  data.push(obj)
})

export default {
  // 页面渲染完毕事件
  mounted() {
    const myChart = echarts.init(this.$refs.myDiv) // 得到图表实例
    myChart.setOption({
      title: {
        text: '基础雷达图'
      },
      tooltip: {},

      radar: {
        // shape: 'circle',
        name: {
          textStyle: {
            color: '#fff',
            backgroundColor: '#999',
            borderRadius: 3,
            padding: [3, 5]
          }
        },
        // 每个区域的最高值
        indicator: [
          { name: '得分', max: 30 },
          { name: '篮板', max: 15 },
          { name: '助攻', max: 10 },
          { name: '盖帽', max: 5 },
          { name: '抢断', max: 5 },
          { name: '失误', max: 5 }
        ]
      },
      series: [{
        name: '预算 vs 开销（Budget vs spending）',
        type: 'radar',
        // areaStyle: {normal: {}},
        data
      }]
    })
  }
}
</script>

<style>
.radar-echart {
    width: 600px;
    height: 400px;
}
</style>
